package br.com.wryel.model;
import java.io.Serializable;

import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

@Component
public class ModelFactory implements ApplicationContextAware {

	private static ApplicationContext applicationContext;
	
	public void setApplicationContext(ApplicationContext applicationContext) {
		currentApplicationContext(applicationContext);
	}
	
	public static void currentApplicationContext(ApplicationContext currentApplicationContext) {
		applicationContext = currentApplicationContext;
	}
	
	public static <CLASS extends GenericModel<? extends Serializable>> CLASS getModelByInterface(Class<CLASS> modelClass) {
		return applicationContext.getBean(StringUtils.uncapitalize(modelClass.getSimpleName()) + "Impl", modelClass);
	}
}
